update_settings(suppress_unused_image_warnings=["server"])

DEBUG = os.environ.get("DEBUG", "true")
IMAGE_TAG = os.environ.get("IMAGE_TAG", "dev")

watch_file('.')

custom_build(
  'airbyte/server',
  '../gradlew :airbyte-server:assemble',
  tag=IMAGE_TAG,
  deps=['src'],
  disable_push=True,
)

template = helm(
  '../charts/airbyte', 
  name='ab', 
  namespace='ab',
  values=['../charts/airbyte/values.yaml'],
  set=[
    'airbyte-bootloader.debug.enabled={}'.format(DEBUG),
    'airbyte-bootloader.image.tag={}'.format(IMAGE_TAG),
    'billing.debug.enabled={}'.format(DEBUG),
    'billing.image.tag={}'.format(IMAGE_TAG),
    'connector-builder-server.debug.enabled={}'.format(DEBUG),
    'connector-builder-server.image.tag={}'.format(IMAGE_TAG),
    'server.debug.enabled={}'.format(DEBUG),
    'server.image.tag={}'.format(IMAGE_TAG),
    'webapp.image.tag={}'.format(IMAGE_TAG),
    'worker.debug.enabled={}'.format(DEBUG),
    'worker.env_vars.CONTAINER_ORCHESTRATOR_IMAGE=airbyte/container-orchestrator:{}'.format(IMAGE_TAG),
    'worker.image.tag={}'.format(IMAGE_TAG)
  ]
)

deployment = filter_yaml(
  template, 
  kind='deployment', 
  name="ab-server",
)

k8s_yaml(deployment[0])
k8s_resource('ab-server', new_name='server', labels='backend')

if DEBUG:
  local('make intellij.config.oss', dir='../../', env={'DEBUG': DEBUG})
